// Created by Xslt generator for Eclipse.
// XSL :  not found (java.io.FileNotFoundException:  (Bad file descriptor))
// Default XSL used : easystruts.jar$org.easystruts.xslgen.JavaClass.xsl

package com.ba360.struts.form;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.ba360.portal.common.PortalConstants;
import com.ba360.portal.database.dbo.User;
import com.ba360.portal.database.dbo.User_23Feb09;
import com.ba360.portal.util.Formatter;

/**
 * RegistrationForm.java created by EasyStruts - XsltGen.
 * http://easystruts.sf.net created on 04-01-2004
 * 
 * XDoclet definition:
 * 
 * @struts:form name="RegistrationForm"
 */
public class RegistrationForm_23Feb09 extends ActionForm {

	// --------------------------------------------------------- Instance
	// Variables

	/** gender property */
	private String gender;
	private String hasacceptedterms;

	/** birthdayMonth property */
	private String birthdayMonth;

	/** address property */
	private String address;

	/** telephone property */
	private String telephone;

	private String password;

	private String repeatpwd;

	/** firstName property */
	private String firstName;

	/** birthdayYear property */
	private String birthdayYear;

	/** birthDayDate property */
	private String birthDayDate;

	/** lastName property */
	private String lastName;

	/** country property */
	private String country;

	/** email property */
	private String email;

	/** state property */
	private String state;

	/** zip property */
	private String zip;

	/** city property */
	private String city;

	// --------------------------------------------------------- Methods

	/**
	 * Method validate
	 * 
	 * @param ActionMapping
	 *            mapping
	 * @param HttpServletRequest
	 *            request
	 * @return ActionErrors
	 */
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {

		ActionErrors errors = null;
		String action = request.getParameter(PortalConstants.ACTION);

		errors = new ActionErrors();
		HttpSession session = request.getSession();
		if (action.equals("Save")) {

			if (hasacceptedterms==null || hasacceptedterms.length()==0)
			{
				errors.add("UserAgreement", new ActionError("error.ua.value"));
				return errors;
			}
			if (firstName == null || firstName.trim().length() == 0)
				errors.add("FirstName", new ActionError("error.fn.value"));
			if (lastName == null || lastName.trim().length() == 0)
				errors.add("LastName", new ActionError("error.ln.value"));
			/*
			 * if (city==null || city.trim().length()==0) errors.add("City",new
			 * ActionError("error.city.value")); if (state==null ||
			 * state.trim().length()==0) errors.add("State",new
			 * ActionError("error.state.value")); if (zip==null ||
			 * zip.trim().length()==0) errors.add("Zip",new
			 * ActionError("error.zip.value"));
			 */
			if (email == null || email.trim().length() == 0)
				errors.add("Email", new ActionError("error.email.value"));
			/*
			 * if (birthDayDate==null || birthdayMonth==null || birthdayYear
			 * ==null) errors.add("Birthday", new
			 * ActionError("error.bday.value")); if (gender==null ||
			 * gender.trim().length()==0) errors.add("Gender", new
			 * ActionError("error.gender.value"));
			 */
			if (email!=null){
				System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@Index of @ in mailid is :"+email.indexOf("@"));
			if (email.indexOf("@") == -1 || email.indexOf(".") == -1
					|| email.length() < 8)
			{
				errors
						.add("Email", new ActionError(
								"error.invalidemail.value"));
				System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@Index of @ in mailid is :"+email.indexOf("@"));
			}
			}
			/* (password == null || password.trim().length() == 0)
				errors.add("Password", new ActionError("error.password.value"));
			if (repeatpwd == null || repeatpwd.trim().length() == 0)
				errors.add("Repeat Password", new ActionError(
						"error.repeatpwd.value"));
			if (!password.equals(repeatpwd))
				errors.add("Password",
						new ActionError("error.password.nomatch"));*/
			password = Formatter.generateRandomPassword();
			repeatpwd = password;
		} 
		
		else if (action.equals("UpdateInfo")) {

			if (firstName == null || firstName.trim().length() == 0)
				errors.add("FirstName", new ActionError("error.fn.value"));
			if (lastName == null || lastName.trim().length() == 0)
				errors.add("LastName", new ActionError("error.ln.value"));
			/*
			 * if (city==null || city.trim().length()==0) errors.add("City",new
			 * ActionError("error.city.value")); if (state==null ||
			 * state.trim().length()==0) errors.add("State",new
			 * ActionError("error.state.value")); if (zip==null ||
			 * zip.trim().length()==0) errors.add("Zip",new
			 * ActionError("error.zip.value"));
			 */
			if (email == null || email.trim().length() == 0)
				errors.add("Email", new ActionError("error.email.value"));
			/*
			 * if (birthDayDate==null || birthdayMonth==null || birthdayYear
			 * ==null) errors.add("Birthday", new
			 * ActionError("error.bday.value")); if (gender==null ||
			 * gender.trim().length()==0) errors.add("Gender", new
			 * ActionError("error.gender.value"));
			 */
			else if (email.indexOf("@") == -1 || email.indexOf(".") == -1
					|| email.length() < 8)
				errors
						.add("Email", new ActionError(
								"error.invalidemail.value"));
			if (password == null || password.trim().length() == 0)
				errors.add("Password", new ActionError("error.password.value"));
			if (repeatpwd == null || repeatpwd.trim().length() == 0)
				errors.add("Repeat Password", new ActionError(
						"error.repeatpwd.value"));
			if (password!=null && repeatpwd!=null){
				if (password.trim().length()<6)
					errors.add("Password",
							new ActionError("error.password.size"));
			if (!password.equals(repeatpwd))
				errors.add("Password",
						new ActionError("error.password.nomatch"));
			
			}
		}
		else if (action.equals("ViewInfo")) {
			//User user = (User) session.getAttribute(PortalConstants.USER); Modified by Arun on 10-MAY-2009
			User_23Feb09 user = (User_23Feb09) session.getAttribute(PortalConstants.USER);
			if (user == null) {
				errors.add("NOT_LOGGED", new ActionError("error.user.nologin"));
				return errors;
			}
			this.address = user.getAddr();
			this.city = user.getCity();
			this.country = user.getCountry();
			this.email = user.getEmail();
			this.firstName = user.getFN();
			this.gender = user.getGender();
			this.lastName = user.getLN();
			this.password = user.getPwd();
			this.repeatpwd = user.getPwd();
			this.state = user.getState();
			this.zip = user.getZip();
			this.telephone = user.getTel();
			//Date bDay = user.getBday();
			//int year = bDay.getYear();
			//this.birthdayYear = year+"";

		}

		return errors;
	}

	/**
	 * Method reset
	 * 
	 * @param ActionMapping
	 *            mapping
	 * @param HttpServletRequest
	 *            request
	 */
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		gender = null;
		birthdayMonth = null;
		address = null;
		telephone = null;
		firstName = null;
		birthdayYear = null;
		birthDayDate = null;
		lastName = null;
		country = null;
		email = null;
		state = null;
		zip = null;
		city = null;
		password = null;
		repeatpwd = null;

	}

	/**
	 * Returns the gender.
	 * 
	 * @return String
	 */
	public String getGender() {
		return gender;
	}

	/**
	 * Set the gender.
	 * 
	 * @param gender
	 *            The gender to set
	 */
	public void setGender(String gender) {
		this.gender = gender;
	}

	public String getPassword() {
		return password;
	}

	/**
	 * Set the gender.
	 * 
	 * @param gender
	 *            The gender to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	public String getrepeatpwd() {
		return repeatpwd;
	}

	/**
	 * Set the gender.
	 * 
	 * @param gender
	 *            The gender to set
	 */
	public void setrepeatpwd(String repeatpwd) {
		this.repeatpwd = repeatpwd;
	}

	/**
	 * Returns the birthdayMonth.
	 * 
	 * @return String
	 */
	public String getBirthdayMonth() {
		return birthdayMonth;
	}

	/**
	 * Set the birthdayMonth.
	 * 
	 * @param birthdayMonth
	 *            The birthdayMonth to set
	 */
	public void setBirthdayMonth(String birthdayMonth) {
		this.birthdayMonth = birthdayMonth;
	}

	/**
	 * Returns the address.
	 * 
	 * @return String
	 */
	public String getAddress() {
		return address;
	}

	/**
	 * Set the address.
	 * 
	 * @param address
	 *            The address to set
	 */
	public void setAddress(String address) {
		this.address = address;
	}

	/**
	 * Returns the telephone.
	 * 
	 * @return String
	 */
	public String getTelephone() {
		return telephone;
	}

	/**
	 * Set the telephone.
	 * 
	 * @param telephone
	 *            The telephone to set
	 */
	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}

	/**
	 * Returns the firstName.
	 * 
	 * @return String
	 */
	public String getFirstName() {
		return firstName;
	}

	/**
	 * Set the firstName.
	 * 
	 * @param firstName
	 *            The firstName to set
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	/**
	 * Returns the birthdayYear.
	 * 
	 * @return String
	 */
	public String getBirthdayYear() {
		return birthdayYear;
	}

	/**
	 * Set the birthdayYear.
	 * 
	 * @param birthdayYear
	 *            The birthdayYear to set
	 */
	public void setBirthdayYear(String birthdayYear) {
		this.birthdayYear = birthdayYear;
	}

	/**
	 * Returns the birthDayDate.
	 * 
	 * @return String
	 */
	public String getBirthDayDate() {
		return birthDayDate;
	}

	/**
	 * Set the birthDayDate.
	 * 
	 * @param birthDayDate
	 *            The birthDayDate to set
	 */
	public void setBirthDayDate(String birthDayDate) {
		this.birthDayDate = birthDayDate;
	}

	/**
	 * Returns the lastName.
	 * 
	 * @return String
	 */
	public String getLastName() {
		return lastName;
	}

	/**
	 * Set the lastName.
	 * 
	 * @param lastName
	 *            The lastName to set
	 */
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	/**
	 * Returns the country.
	 * 
	 * @return String
	 */
	public String getCountry() {
		return country;
	}

	/**
	 * Set the country.
	 * 
	 * @param country
	 *            The country to set
	 */
	public void setCountry(String country) {
		this.country = country;
	}

	/**
	 * Returns the email.
	 * 
	 * @return String
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * Set the email.
	 * 
	 * @param email
	 *            The email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * Returns the state.
	 * 
	 * @return String
	 */
	public String getState() {
		return state;
	}

	/**
	 * Set the state.
	 * 
	 * @param state
	 *            The state to set
	 */
	public void setState(String state) {
		this.state = state;
	}

	/**
	 * Returns the zip.
	 * 
	 * @return String
	 */
	public String getZip() {
		return zip;
	}

	/**
	 * Set the zip.
	 * 
	 * @param zip
	 *            The zip to set
	 */
	public void setZip(String zip) {
		this.zip = zip;
	}

	/**
	 * Returns the city.
	 * 
	 * @return String
	 */
	public String getCity() {
		return city;
	}

	/**
	 * Set the city.
	 * 
	 * @param city
	 *            The city to set
	 */
	public void setCity(String city) {
		this.city = city;
	}
	
	public String getHasacceptedterms() {
		return hasacceptedterms;
	}
	public void setHasacceptedterms(String hasacceptedterms) {
		this.hasacceptedterms = hasacceptedterms;
	}

}